﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericGridControl.Model;

namespace OpenLS.Spreadsheet
{
    public class TableDefinedName : DefinedName
    {
          
         internal TableDefinedName(Workbook workbook)
        {
            if (workbook == null)
                throw new ArgumentNullException("workbook");
            _workbook = workbook;
            Name = Enumerable.First(getAllNames(), n => Enumerable.All(_workbook.TableDefinedNames,
                                                                       dn => string.Compare(dn.Name, n, true) != 0));

        }


        internal TableDefinedName(Workbook workbook, string name, bool isPublic)
            : this(workbook)
        {
            if (!isValidName(name))
                throw new ArgumentException("name");
            if (Enumerable.Any(_workbook.TableDefinedNames, dn => string.Compare(dn.Name, name, true) == 0))
                throw new ArgumentException("name");
            if (!BigDataTableStaticDAL.CheckNameAvailability(name, isPublic))
                throw new ArgumentException("name");

            Name = name;
        }
    }
}
